//输入正确的总数量
var num = 0
//获取病历号
var oInpA = document.querySelector('.medicalRecord input')
//获取病人信息的输入框
var oName = document.querySelector('.patientInformation-textA')
var oAge = document.querySelector('.patientInformation-textB')
//获取补救措施框
var toSave = document.querySelector('.bujiu')
//按钮提交
var toSubmit = document.querySelector('.toSubmit')
//病历号正则
oInpA.onblur = function () {
  var strA = this.value
  var regA = /\d{14}/
  if (strA.trim == 0) {
    alert('病历号不能为空！')
  } else if (regA.test(strA) == false) {
    this.nextElementSibling.className = 'imgOneUp'
    this.value = ''
  } else {
    num++
    this.nextElementSibling.className = 'imgOne'
    console.log(num)
  }
}
//病人信息正则
//姓名
oName.onblur = function () {
  var strB = this.value
  var regB = /^[\u4e00-\u9fa5]{2,6}$/
  if (strB.trim == 0) {
    alert('姓名不能为空！')
  } else if (regB.test(strB) == false) {
    this.nextElementSibling.className = 'imgOneUp'
    this.value = ''
  } else {
    num++
    this.nextElementSibling.className = 'imgOne'
    console.log(num)
  }
}
//年龄
oAge.onblur = function () {
  var strC = this.value
  var regC = /^(?:[1-9][0-9]?|1[01][0-9]|120)$/
  if (strC.trim == 0) {
    alert('年龄不能为空！')
  } else if (regC.test(strC) == false) {
    this.nextElementSibling.className = 'imgOneUp'
    this.value = ''
  } else {
    num++
    this.nextElementSibling.className = 'imgOne'
    console.log(num)
  }
}
//提交按钮
toSubmit.onclick = function () {
  if (num == 3) {
    alert('恭喜你提交成功!')
    oInpA.value = ''
    oName.value = ''
    oAge.value = ''
  } else {
    alert('信息不对，请重新检查信息！')
  }
}
